iconEuler Examples

LPSOLVE Demos

by P. Notebaert

These demos demonstrate how to use the LPSOLVE package in Euler. For further reference, see the LPSOLVE page.

LPSOLVE at Sourceforge

>load "lpsolve"
Routines for the LPSOLVE library.

Example 1

>lp=eulpsolve("make_lp",0,4);
>eulpsolve("set_verbose", lp, 3);
>eulpsolve("add_constraint",lp,[3, 2, 2, 1],3,4);
>eulpsolve("add_constraint",lp,[0, 4, 3, 1],2,3);
>eulpsolve("set_obj_fn",lp,[2, 3, -2, 3]);
>result=eulpsolve("solve",lp)
0
>obj=eulpsolve("get_objective", lp)
-4
>x=eulpsolve("get_variables", lp)
            0 
            0 
            2 
            0 
>eulpsolve("set_mat",lp,2,1,0.5);
>eulpsolve("set_maxim",lp);
>result=eulpsolve("solve",lp)
0
>obj=eulpsolve("get_objective", lp)
12
>x=eulpsolve("get_variables", lp)
            0 
            0 
            0 
            4 
>eulpsolve("set_rh",lp,1,7.45);
>result=eulpsolve("solve",lp)
0
>obj=eulpsolve("get_objective", lp)
22.35
>x=eulpsolve("get_variables", lp)
            0 
            0 
            0 
         7.45 
>eulpsolve("set_int",lp,4,1)
1
>result=eulpsolve("solve",lp)
0
>obj=eulpsolve("get_objective", lp)
21.675
>x=eulpsolve("get_variables", lp)
            0 
        0.225 
            0 
            7 
>eulpsolve("set_lowbo",lp,2,2);
>eulpsolve("set_upbo",lp,4,5.3);
>result=eulpsolve("solve",lp)
0
>obj=eulpsolve("get_objective", lp)
15.675
>x=eulpsolve("get_variables", lp)
            0 
        2.225 
            0 
            3 
>eulpsolve("del_constraint",lp,1);
>eulpsolve("add_constraint",lp,[1, 2, 1, 4],3,8);
>result=eulpsolve("solve",lp)
0
>obj=eulpsolve("get_objective", lp)
14
>x=eulpsolve("get_variables", lp)
            4 
            2 
            0 
            0 
>eulpsolve("delete_lp",lp);
>lp=eulpsolve("make_lp",2,2);
>eulpsolve("set_verbose", lp, 3);
>eulpsolve("set_mat",lp,[2, 1;-4, 4]);
>eulpsolve("set_obj_fn",lp,[-1, 2]);
>eulpsolve("set_int",lp,[1,1]);
>eulpsolve("set_rh_vec",lp,[5, 5]);
>eulpsolve("set_maxim",lp);
>result=eulpsolve("solve",lp)
0
>obj=eulpsolve("get_objective", lp)
3
>x=eulpsolve("get_variables", lp)
            1 
            2 
>eulpsolve("delete_lp",lp);
>f = [50, 100];
>A = [10, 5;4, 10; 1, 1.5];
>b = [2500, 2000, 450];
>e = [-1, -1, -1];
>m = rows(A);
>n = cols(A);
>lp=eulpsolve("make_lp",m,n);
>eulpsolve("set_verbose", lp, 3);
>eulpsolve("set_obj_fn",lp,f);
>eulpsolve("set_mat",lp,A);
>eulpsolve("set_rh_vec",lp,b);
>eulpsolve("set_maxim",lp);
>result=eulpsolve("solve",lp)
0
>obj=eulpsolve("get_objective", lp)
21875
>x=eulpsolve("get_variables", lp)
        187.5 
          125 
>eulpsolve("delete_lp",lp);
>f = -[40, 36];
>vub = [8, 10];
>A = [5, 3];
>b = [45];
>e = 1;
>m = rows(A);
>n = cols(A);
>lp=eulpsolve("make_lp",m,n);
>eulpsolve("set_verbose", lp, 3);
>eulpsolve("set_obj_fn",lp,f);
>eulpsolve("set_mat",lp,A);
>eulpsolve("set_rh_vec",lp,b);
>eulpsolve("set_constr_type",lp,1,2);
>eulpsolve("set_upbo",lp,1,8);
>eulpsolve("set_upbo",lp,2,10);
>eulpsolve("set_maxim",lp);
>result=eulpsolve("solve",lp)
0
>obj=eulpsolve("get_objective", lp)
-380
>x=eulpsolve("get_variables", lp)
            8 
      1.66667 
>eulpsolve("delete_lp",lp);

Example 2

>lp=eulpsolve("make_lp", 0, 4);
>eulpsolve("set_verbose", lp, 3);
>eulpsolve("set_obj_fn", lp, [1, 3, 6.24, 0.1]);
>eulpsolve("add_constraint", lp, [0, 78.26, 0, 2.9], 2, 92.3);
>eulpsolve("add_constraint", lp, [0.24, 0, 11.31, 0], 1, 14.8);
>eulpsolve("add_constraint", lp, [12.68, 0, 0.08, 0.9], 2, 4);
>eulpsolve("set_lowbo", lp, 1, 28.6);
>eulpsolve("set_lowbo", lp, 4, 18);
>eulpsolve("set_upbo", lp, 4, 48.98);
>eulpsolve("set_col_name", lp, 1, "COLONE");
>eulpsolve("set_col_name", lp, 2, "COLTWO");
>eulpsolve("set_col_name", lp, 3, "COLTHREE");
>eulpsolve("set_col_name", lp, 4, "COLFOUR");
>eulpsolve("set_row_name", lp, 1, "THISROW");
>eulpsolve("set_row_name", lp, 2, "THATROW");
>eulpsolve("set_row_name", lp, 3, "LASTROW");
>eulpsolve("write_lp", lp, "a.lp");
>eulpsolve("get_mat", lp, 1, 2)
78.26
>eulpsolve("solve", lp)
0
>eulpsolve("get_objective", lp)
31.7827586207
>eulpsolve("get_variables", lp)
         28.6 
            0 
            0 
      31.8276 
>eulpsolve("get_constraints", lp)
         92.3 
        6.864 
      391.293 
>eulpsolve("delete_lp", lp);

Example 3

>lp=eulpsolve("make_lp", 0, 4);
>eulpsolve("set_verbose", lp, 3);
>eulpsolve("set_obj_fn", lp, [1, 3, 6.24, 0.1]);
>eulpsolve("add_constraint", lp, [0, 78.26, 0, 2.9], 2, 92.3);
>eulpsolve("add_constraint", lp, [0.24, 0, 11.31, 0], 1, 14.8);
>eulpsolve("add_constraint", lp, [12.68, 0, 0.08, 0.9], 2, 4);
>eulpsolve("set_lowbo", lp, [28.6, 0, 0, 18]);
>eulpsolve("set_upbo", lp, [1.0e30, 1.0e30, 1.0e30, 48.98]);
>eulpsolve("set_col_name", lp, 1, "COLONE");
>eulpsolve("set_col_name", lp, 2, "COLTWO");
>eulpsolve("set_col_name", lp, 3, "COLTHREE");
>eulpsolve("set_col_name", lp, 4, "COLFOUR");
>eulpsolve("set_row_name", lp, 1, "THISROW");
>eulpsolve("set_row_name", lp, 2, "THATROW");
>eulpsolve("set_row_name", lp, 3, "LASTROW");
>eulpsolve("write_lp", lp, "a.lp");
>eulpsolve("get_mat", lp)
            0         78.26             0           2.9 
         0.24             0         11.31             0 
        12.68             0          0.08           0.9 
>eulpsolve("solve", lp)
0
>eulpsolve("get_objective", lp)
31.7827586207
>eulpsolve("get_variables", lp)
         28.6 
            0 
            0 
      31.8276 
>eulpsolve("get_constraints", lp)
         92.3 
        6.864 
      391.293 
>eulpsolve("delete_lp", lp);

Example 4

>f = [143,60];
>A = [120, 210; 110, 30; 1, 1];
>b = [15000; 4000; 75];
>lp = lpmaker(f, A, b, [-1; -1; -1], [], [], [], 1, 0);
>solvestat = eulpsolve("solve", lp);
>obj = eulpsolve("get_objective", lp)
6315.625
>x = eulpsolve("get_variables", lp)
       21.875 
       53.125 
>eulpsolve("delete_lp", lp);

Example 5

>f = [143, 60, 195];
>A = [120, 210, 150.75; 110, 30, 125; 1, 1, 1];
>b = [15000; 4000; 75];
>lp = lpmaker(f, A, b, [-1, -1, -1], [], [], [], 1, 0);
>solvestat = eulpsolve("solve", lp);
>eulpsolve("get_objective", lp)
6986.84210526
>eulpsolve("get_variables", lp)
            0 
      56.5789 
      18.4211 
>eulpsolve("delete_lp", lp);

Example 6

>f = [110*1.3, 30*2.0, 125*1.56, 75*1.8, 95*.95, 100*2.25, 50*1.35];
>A = [120,210,150.75,115,186,140,85;  ...
 110,30,125,75,95,100,50;  ...
 1,1,1,1,1,1,1;  ...
 1,-1,0,0,0,0,0;  ...
 0,0,1,0,-2,0,0;  ...
 0,0,0,-1,0,-1,1];
>b = [55000; 40000; 400; 0; 0; 0];
>lp = lpmaker(f, A, b, [-1,-1,-1,-1,-1,-1], ...
   [10,10,10,10,20,20,20],[100,1.0e30,50,1.0e30,1.0e30,250,1.0e30], ...
   [],1,0);
>solvestat = eulpsolve("solve", lp);
>obj = eulpsolve("get_objective", lp)
75398.0434783
>x = eulpsolve("get_variables", lp)
           10 
           10 
           40 
      45.6522 
           20 
          250 
           20 
>eulpsolve("delete_lp", lp);

Examples